home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 8206 / 8206.xpi / content / service.xml < prev    next >
Extensible Markup Language  |  2010-02-02  |  11KB  |  291 lines

  1. <?xml version="1.0"?>
  2. <!DOCTYPE bindings PUBLIC "-//MOZILLA//DTD XBL V1.0//EN" "http://www.mozilla.org/xbl">
  3.  
  4. <bindings
  5.     xmlns="http://www.mozilla.org/xbl"
  6.     xmlns:xbl="http://www.mozilla.org/xbl"
  7.     xmlns:html="http://www.w3.org/1999/xhtml"
  8.     xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  9.  
  10.   <binding id="service-base">
  11.     <content>
  12.       <xul:hbox anonid="img-box" popup="_child" pack="center" align="center" style="padding-left: 2px">
  13.         <xul:image anonid="service-dropdown" src="chrome://wisestamp/skin/narrow.png"/>
  14.         <xul:hbox width="16" height="16" pack="center" align="center">
  15.           <xul:image anonid="img-current" width="16" height="16" style="margin-right: 5px"/>
  16.         </xul:hbox>
  17.         <xul:image anonid="img-box-arrow"/>
  18.         <xul:menupopup anonid="service-popup" position="after_start"
  19.               onpopupshowing="this.parentNode.parentNode.servicePopupShowing(event);"
  20.               onpopupshown="this.parentNode.parentNode.servicePopupShown(event);">
  21.  
  22.         </xul:menupopup>
  23.       </xul:hbox>
  24.       <xul:textbox anonid="textbox" flex="1"  xbl:inherits="value"/>
  25.       <xul:hbox anonid="question-block" tooltip="_child" align="center" pack="center" width="20">
  26.         <xul:image src="chrome://wisestamp/skin/question.png" anonid="question" width="15" height="15" />
  27.         <xul:tooltip anonid="help-popup" style="max-width: 600px;" onpopupshown="this.parentNode.parentNode.serviceHelpShown(event)">
  28.             <xul:image anonid="help-image"/>
  29.         </xul:tooltip>
  30.       </xul:hbox>
  31.     </content>
  32.  
  33.     <implementation>
  34.       <constructor>
  35.       <![CDATA[
  36.         if (this.service){
  37.           this.init();
  38.         }
  39.       ]]>
  40.       </constructor>
  41.       <field name="_service">null</field>
  42.       <property name="service" >
  43.         <getter>
  44.         <![CDATA[
  45.           if (!this._service)
  46.             this._service = this.getAttribute("service");
  47.           return this._service;
  48.         ]]>
  49.         </getter>
  50.         <setter>
  51.         <![CDATA[
  52.           if (this._service){
  53.             this.parentNode.setAttribute("value",
  54.             this.parentNode.getAttribute("value").replace(this._service,val));
  55.           }
  56.           this.setAttribute("service", val);
  57.           this._service = val;
  58.         ]]>
  59.         </setter>
  60.       </property>
  61.       <property name="prefs">
  62.         <getter>
  63.           if (!this._prefs){
  64.             this._prefs = Components.classes["@mozilla.org/preferences-service;1"].
  65.                           getService(Components.interfaces.nsIPrefService);
  66.             this._prefs = this._prefs.getBranch("extensions.wisestamp.");
  67.           }
  68.           return this._prefs;
  69.         </getter>
  70.       </property>
  71.       <field name="_strings">null</field>
  72.       <property name="strings">
  73.         <getter>
  74.         <![CDATA[
  75.           if (!this._strings){
  76.             this._strings = Components.classes["@mozilla.org/intl/stringbundle;1"].getService(Components.interfaces.nsIStringBundleService);
  77.             this._strings = this._strings.createBundle("chrome://wisestamp/locale/wisestamp.properties");
  78.           }
  79.           return this._strings;
  80.         ]]>
  81.         </getter>
  82.       </property>
  83.       <field name="textbox">document.getAnonymousElementByAttribute(this, "anonid","textbox")</field>
  84.       <property name="value" onget="return this.textbox.value"
  85.                              onset="this.textbox.value = val;"/>
  86.       <method name="initIcon">
  87.         <parameter name="aFolder"/>
  88.         <parameter name="aType"/>
  89.         <body>
  90.         <![CDATA[
  91.           //var serviceLabel = document.getAnonymousElementByAttribute
  92.           //      (this,"anonid","service-label");
  93.           //serviceLabel.value = this.service;
  94.  
  95.           var imageBox = document.getAnonymousElementByAttribute(this,"anonid","img-box");
  96.           imageBox.setAttribute("tooltiptext",this.strings.GetStringFromName(this.service));
  97.           var currentImage = document.getAnonymousElementByAttribute(this,"anonid","img-current");
  98.           currentImage.src = "chrome://wisestamp/skin/icons/"+this.service+".png";
  99.  
  100.           this.textbox.emptyText = this.strings.GetStringFromName(aType+"-emptytext");
  101.           
  102.           var services = this.prefs.getCharPref(aType).split(",");
  103.           var popup = document.getAnonymousElementByAttribute(this,"anonid","service-popup");
  104.  
  105.           while(popup.lastChild)
  106.             popup.removeChild(popup.lastChild);
  107.           var xulns = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
  108.           for (var i = 0;i<services.length;i++){
  109.             var id = services[i];
  110.             if (id != this.service){
  111.               var menuitem = document.createElementNS(xulns, "menuitem");
  112.               menuitem.setAttribute("label",this.strings.GetStringFromName(id));
  113.               menuitem.setAttribute("tooltiptext",this.strings.GetStringFromName(id));
  114.               menuitem.setAttribute("class","menuitem-iconic");
  115.               menuitem.setAttribute("style","list-style-image: url('chrome://wisestamp/skin/icons/"+id+".png'); margin-top: 1px;");
  116.               menuitem.setAttribute("oncommand", "this.parentNode.parentNode." + "parentNode.switchTo('"+id+"')");
  117.               popup.appendChild(menuitem);
  118.             }
  119.           }
  120.           popup.appendChild(document.createElement("menuseparator"));
  121.           var menuitem = document.createElementNS(xulns, "menuitem");
  122.           menuitem.setAttribute("label",this.strings.
  123.               GetStringFromName("removeService"));
  124.           menuitem.setAttribute("class","menuitem-iconic remove-service");
  125.           //menuitem.setAttribute("style","list-style-image: url('chrome://wisestamp/skin/icons/"+
  126.           //  id+".png')");
  127.           menuitem.setAttribute("oncommand", "this.parentNode.parentNode." + "parentNode.remove()");
  128.           popup.appendChild(menuitem);
  129.         ]]>
  130.         </body>
  131.       </method>
  132.       <method name="remove">
  133.         <body>
  134.         <![CDATA[
  135.           var val = this.parentNode.getAttribute("value").split(/\s*,\s*/);
  136.           var idx = val.indexOf(this.service);
  137.           val.splice(idx,1);
  138.           this.parentNode.setAttribute("value",val.join(","));
  139.           this.parentNode.removeChild(this);
  140.         ]]>
  141.         </body>
  142.       </method>
  143.       <method name="servicePopupShown">
  144.         <parameter name="aEvent"/>
  145.         <body>
  146.         <![CDATA[
  147.         ]]>
  148.         </body>
  149.       </method>
  150.       <method name="servicePopupShowing">
  151.         <parameter name="aEvent"/>
  152.         <body>
  153.         <![CDATA[
  154.         ]]>
  155.         </body>
  156.       </method>
  157. <!--      <method name="WISELOG">-->
  158. <!--        <parameter name="msg"/>-->
  159. <!--        <body>-->
  160. <!--        <![CDATA[-->
  161. <!--          Components.utils.reportError(msg);-->
  162. <!--          var consoleService = Components.classes["@mozilla.org/consoleservice;1"]-->
  163. <!--                                 .getService(Components.interfaces.nsIConsoleService);-->
  164. <!--          consoleService.logStringMessage(msg);-->
  165. <!--        ]]>-->
  166. <!--        </body>-->
  167. <!--      </method>-->
  168.     </implementation>
  169.  
  170.  
  171.     <handlers>
  172.     </handlers>
  173.   </binding>
  174.   <binding id="service" extends="chrome://wisestamp/content/service.xml#service-base">
  175.     <implementation>
  176.       <method name="switchTo">
  177.         <parameter name="aService"/>
  178.         <body>
  179.         <![CDATA[
  180. <!--          dump("switch to: "+aService+"\n");-->
  181.           this.service = aService;
  182.           var popup = document.getAnonymousElementByAttribute(this,"anonid","service-popup");
  183.           popup.hidePopup();
  184.           var vals = WiseStampOptions.data.sigs[WiseStampOptions.type].services[aService];
  185.           var used = this.parentNode.getAttribute("value").split(",");
  186.           var idx = 0;
  187.           for (var i=0;i<used.length;i++){
  188.             if (used[i]==aService)
  189.               idx++;
  190.           }
  191.           var val = vals[idx];
  192.           if (!val || val=="undefined")
  193.             val = "";
  194.           this.value = val;
  195.           this.init();
  196.           this.textbox.focus();
  197.         ]]>
  198.         </body>
  199.       </method>
  200.       <method name="init">
  201.         <body>
  202.         <![CDATA[
  203.           this.initIcon("socialservices","services");
  204.         ]]>
  205.         </body>
  206.       </method>
  207.       <method name="servicePopupShowing">
  208.         <parameter name="aEvent"/>
  209.         <body>
  210.         <![CDATA[
  211.         ]]>
  212.         </body>
  213.       </method>
  214.       <method name="servicePopupShown">
  215.         <parameter name="aEvent"/>
  216.         <body>
  217.         <![CDATA[
  218. <!--          dump("service popup shown: "+aEvent+"\n")-->
  219.           //var diff = screen.height - aEvent.target.boxObject.y - aEvent.target.boxObject.height - 110;
  220. <!--          //dump("diff: "+diff+"\n");-->
  221.           //aEvent.target.setAttribute("height",diff);
  222.           //aEvent.target.sizeTo(aEvent.target.boxObject.width,diff);
  223.         ]]>
  224.         </body>
  225.       </method>
  226.       <method name="serviceHelpShown">
  227.         <parameter name="aEvent"/>
  228.         <body>
  229.         <![CDATA[
  230.           var src = "chrome://wisestamp/skin/url-example/"+this.service+".png";
  231.           var imageEle = document.getAnonymousElementByAttribute(this,"anonid","help-image");
  232.           imageEle.setAttribute("src",src);
  233.         ]]>
  234.         </body>
  235.       </method>
  236.     </implementation>
  237.   </binding>
  238.   <binding id="im" extends="chrome://wisestamp/content/service.xml#service-base">
  239.     <implementation>
  240.       <constructor>
  241.         document.getAnonymousElementByAttribute(this,"anonid","question-block").hidden = true;
  242.       </constructor>
  243.       <method name="switchTo">
  244.         <parameter name="aService"/>
  245.         <body>
  246.         <![CDATA[
  247.           this.service = aService;
  248.           var popup = document.getAnonymousElementByAttribute(this,"anonid","service-popup");
  249.           popup.hidePopup();
  250.           var vals = WiseStampOptions.data.sigs[WiseStampOptions.type].im[aService];
  251.           var used = this.parentNode.getAttribute("value").split(",");
  252.           var idx = -1;
  253.           for (var i=0;i<used.length;i++){
  254.             if (used[i]==aService)
  255.               idx++;
  256.           }
  257. <!--          dump("indx: "+idx+"\n")-->
  258.           var val = vals[idx];
  259.           if (!val || val=="undefined")
  260.             val = "";
  261.           this.value = val;
  262.           this.init();
  263.           this.textbox.focus();
  264.         ]]>
  265.         </body>
  266.       </method>
  267.       <method name="init">
  268.         <body>
  269.         <![CDATA[
  270.           this.initIcon("im","im");
  271.         ]]>
  272.         </body>
  273.       </method>
  274.       <method name="serviceHelpShown">
  275.         <parameter name="aEvent"/>
  276.         <body>
  277.         <![CDATA[
  278.           return false;
  279.         ]]>
  280.         </body>
  281.       </method>
  282.       <method name="servicePopupShowing">
  283.         <parameter name="aEvent"/>
  284.         <body>
  285.         <![CDATA[
  286.         ]]>
  287.         </body>
  288.       </method>
  289.     </implementation>
  290.   </binding>
  291. </bindings>